<template>
  <div class="goods-hot">
    <h3>{{title}}</h3>
    <!-- 商品区块 -->
    <RouterLink to="/" class="goods-item" v-for="goods in goodsList" :key="goods.id">
      <img
        :src="goods.picture"
        alt=""
      />
      <p class="name ellipsis">{{goods.name}}</p>
      <p class="desc ellipsis">{{goods.desc}}</p>
      <p class="price">&yen;{{goods.price}}</p>
    </RouterLink>
  </div>
</template>
<script>
import { findHotGoods } from '@/api/goods'
import { computed, ref } from 'vue'
import { useRoute } from 'vue-router'
export default {
  name: 'GoodsHot',
  props: {
    type: {
      type: Number
    }
  },
  setup (props) {
    const goodsList = ref([])
    const route = useRoute()
    async function loadGoodsListFn () {
      const res = await findHotGoods({
        id: route.params.id,
        type: props.type
      })
      goodsList.value = res.data.result
    }
    loadGoodsListFn()

    const mj = {
      1: '24小时热销榜',
      2: '周热销榜',
      3: '月热销榜'
    }

    const title = computed(() => {
      return mj[props.type]
    })
    return {
      goodsList,
      title
    }
  }
}
</script>
<style scoped lang="less">
.goods-hot {
  h3 {
    height: 70px;
    background: @helpColor;
    color: #fff;
    font-size: 18px;
    line-height: 70px;
    padding-left: 25px;
    margin-bottom: 10px;
    font-weight: normal;
  }
}
.goods-item {
    display: block;
    // width: 220px;
    // padding: 20px 30px;
    padding: 20px 0;
    text-align: center;
    // img {
    //   width: 160px;
    //   height: 160px;
    // }
    p {
      padding-top: 10px;
    }
    .name {
      font-size: 16px;
    }
    .desc {
      color: #999;
      height: 29px;
    }
    .price {
      color: @priceColor;
      font-size: 20px;
    }
  }
</style>
